<div style="float: right;">
    <a href="<?=base_url("no_edit/music/add_music")?>" class="layui-btn">新增音效分类</a>
    <button class="layui-btn fabu">发布</button>
</div>
<br><br>
<br><br>
<table class="layui-table">
    <colgroup>
        <col width="15%">
        <col width="10%">
        <col width="5%">
        <col width="5%">
        <col width="5%">
        <col width="20%">
    </colgroup>
    <thead>
    <tr>
        <th>封面</th>
        <th>名称</th>
        <th>数量</th>
        <th>状态</th>
        <th>使用次数</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php if(!empty($data)){
        foreach($data as $k=>$v){
            $length=count($data);//统计这个数组有多少个
            ?>
            <tr>
                <td>
                    <img src="<?=$v['test_music_type_icon']?>" style="width:30%;height:80px;" class="tom_show_image imgs<?=$k?>">
                </td>
                <td><?=$v['test_music_type_name']?></td>
                <td><?=$v['nums']?></td>
                <?php if($v['test_music_type_status']==1){ ?>
                    <td>已下线</td>
                <?php }else if($v['test_music_type_status']==2){ ?>
                    <td>已上线</td>
                <?php } ?>
                <td><?=$v['music_use_num']?></td>
                <td>
                    <a href="<?=base_url("no_edit/music/edit?id={$v['id']}")?>" class="layui-btn layui-btn-xs">内容编辑</a>
                    <?php if($v['test_music_type_status']==1){ ?>
                        <button class="layui-btn layui-btn-xs layui-btn-normal start<?=$k?>">启用</button>
                    <?php }else if($v['test_music_type_status']==2){ ?>
                        <button class="layui-btn layui-btn-xs layui-btn-danger stop<?=$k?>">停用</button>
                    <?php } ?>
                    <button class="layui-btn layui-btn-xs layui-btn-warm up<?=$k?>">上移</button>
                    <button class="layui-btn layui-btn-xs layui-btn-warm down<?=$k?>">下移</button>
                    <input type="hidden" value="<?=$v['id']?>" class="ids<?=$k?>">
                </td>
            </tr>
            <?php if($k==0){ ?>
                <input type="hidden" name="" value="<?=$data[0]['id']?>" class="start1<?=$k;?>">
            <?php }else{ ?>
                <input type="hidden" name="" value="<?=$data[$k-1]['id']?>" class="start1<?=$k;?>">
            <?php } ?>
            <?php if($k==$length-1){ ?>
                <input type="hidden" name="" value="<?=$data[$length-1]['id']?>" class="end1<?=$k;?>">
            <?php }else{ ?>
                <input type="hidden" name="" value="<?=$data[$k+1]['id']?>" class="end1<?=$k;?>">
            <?php } ?>
        <?php }}else{ ?>
        <tr>
            <td colspan="7" rowspan="3" style="color: #00CC00;font-size: 25px;height:100px;text-align: center;">暂无数据</td>
        </tr>
    <?php } ?>
    </tbody>
</table>

<script>
    $('.fabu').click(function(){
        $.ajax({
            type: "post",
            data: {},
            dataType: "json",
            url: "<?=base_url("no_edit/music/fabu")?>",
            success: function (res) {
                if(res.code==0){
                    layer.msg(res.msg, {time: 2000},function(){
                        window.location.reload()
                    });
                }else{
                    layer.msg(res.msg, {time: 2000});
                }
            }
        })
    })
    //定义一个50的jquery数组
    var arr=[];
    for(var i=0;i<51;i++){
        arr.push(i)
    }
    $.each(arr,function(i,n){
        var id=$('.ids'+n).val()
        //1.启用
        $(".start"+n).click(function(){
            $.ajax({
                type: "post",
                data: {id:id},
                dataType: "json",
                url: "<?=base_url("no_edit/music/start_type")?>",
                success: function (res) {
                    if(res.code==0){
                        layer.msg(res.msg, {time: 2000},function(){
                            window.location.reload()
                        });
                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                }
            })
        })
        //2.停用
        $(".stop"+n).click(function(){
            $.ajax({
                type: "post",
                data: {id:id},
                dataType: "json",
                url: "<?=base_url("no_edit/music/stop_type")?>",
                success: function (res) {
                    if(res.code==0){
                        layer.msg(res.msg, {time: 2000},function(){
                            window.location.reload()
                        });
                    }else{
                        layer.msg(res.msg, {time: 2000});
                    }
                }
            })
        })
        //3.上移
        $(".up"+n).click(function(){
            var start_id=$('.start1'+n).val()
            if(start_id==id){
                layer.msg("当前已为第一个")
                return false;
            }else{
                $.ajax({
                    type: "post",
                    data: {id:id,start_id:start_id},
                    dataType: "json",
                    url: "<?=base_url("no_edit/music/up_type")?>",
                    success: function (res) {
                        if(res.code==0){
                            layer.msg(res.msg, {time: 2000},function(){
                                window.location.reload()
                            });
                        }else{
                            layer.msg(res.msg, {time: 2000});
                        }
                    }
                })
            }
        })
        //4.下移
        $(".down"+n).click(function(){
            var end_id=$('.end1'+n).val()
            if(end_id==id){
                layer.msg("当前已为最后一个")
                return false;
            }else{
                $.ajax({
                    type: "post",
                    data: {id:id,end_id:end_id},
                    dataType: "json",
                    url: "<?=base_url("no_edit/music/down_type")?>",
                    success: function (res) {
                        if(res.code==0){
                            layer.msg(res.msg, {time: 2000},function(){
                                window.location.reload()
                            });
                        }else{
                            layer.msg(res.msg, {time: 2000});
                        }
                    }
                })
            }
        })
    })
</script>
